﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace FaceRecognition
{
    public partial class frmDetected : Form
    {
        private int _faceIndex = 0;

        public frmDetected()
        {
            InitializeComponent();
        }

        private void frmDetected_Load(object sender, EventArgs e)
        {
            ShowImage();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _faceIndex++;
            ShowImage();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            _faceIndex--;
            ShowImage();
        }

        private void ShowImage()
        {
            try
            {
                _faceIndex = ObjRec.ExternalFunctions.Clamp(_faceIndex, 0, Form1._fr._faces.Length - 1);
                pictureBox1.Image = Form1._fr.GetFace(_faceIndex);
                if(Form1._fr._isTrained) textBox1.Text = Form1._fr.Recognize(Form1._fr._faces[_faceIndex]);
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            try
            {
                Form1._fr.AddPerson(textBox1.Text, new Bitmap(pictureBox1.Image));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
    }
}
